package com.zhengjiang.lambda;

/**
 * @author zhengjiang
 * @version 1.0.0
 * @description lambda方法引用
 *
 * @date 2021/5/30
 **/
public class MethodRefer {
    public static void main(String[] args) {
        Converter converter = from -> Integer.valueOf(from);
        System.out.println(converter.convert("100"));

        //类方法引用
        Converter converter1 = Integer::valueOf;
        System.out.println(converter1.convert("99"));

        //特定对象的实例方法引用
        converter = from -> "abcdefg".indexOf(from);
        System.out.println(converter.convert("e"));
        Converter converter2 = "abcdefg"::indexOf;
        System.out.println(converter2.convert("b"));


        //类对象的实例方法引用
        MyTest mt = (s,first,last) -> s.substring(first,last);
        System.out.println(mt.test("abcdef",0,2));
        mt = String::substring;
        System.out.println(mt.test("abcdef",0,2));
    }
}


@FunctionalInterface
interface Converter{
    Integer convert(String from );
}

@FunctionalInterface
interface MyTest {
    String test(String s, int first, int last);
}
